$(function () {

    $('#table').bootstrapTable({
        url: '${pageContext.request.contextPath}/../../house/list',
        columns: [
            {
                field: 'id',
                title: 'id',
                visible : false,
            },{
                field: 'doornumber',
                title: '房屋门牌号'
            }, {
                field: 'typeb.id',
                title: '房屋状态',
                formatter: function (value, row, index) {
                    if (row.typeb.id == 1) {
                        return "空闲";
                    } else {
                        return "已售";
                    }
                }

            },{
                field: 'sale.name',
                title: '楼'
            }, {
                field: 'danyuan.name',
                title: '单元'
            }, {
                field: 'floor',
                title: '层数'
            }, {
                field: 'huxing.name',
                title: '户型'
            }, {
                field: 'direction.name',
                title: '房屋朝向'
            }, {
                field: 'measure',
                title: '房屋面积',
                formatter: function (value, row, index) {
                    var jia = row .measure+"平方米";
                    return jia;
                }
            },{
                field:'remark',
                title:'简介'
            }
        ],onDblClickRow: function (row, $element, field) {
            // 清空

            $("#name").val("");
            $("#money").val("");
            $("#date").val("");
            $("#xuan").val(1);
            $("#sfz").val("");
            $("#uname").val("");
            $("#phone").val("");
            $("#remark").val("");
            $("#yin").val("");
            $("#yin2").val("");

            //$("#myModal2").modal('show');
            $('#your-modal').modal(open);
            $("#xx").text("百家小区"+row.sale.name+""+row.danyuan.name+""+row.doornumber+"号");
            $("#type1").text(row.typeb.name);
            $("#huxing").text(row.huxing.name);
            $("#chaoxiang").text(row.direction.name);
            $("#mianji").text(row.measure+"平方米");
            $("#yin2").val(row.id);
            // 人
            if(row.userdetails==null){
                $("#name").val(row.doornumber);
                $("#yin2").val(row.id);
            }else{
                var c;
                $.ajax({
                    type : "post",
                    url : "${pageContext.request.contextPath}/../../salesrecord/quan",
                    async : false,
                    data : {
                        "number" : row.doornumber
                    },
                    datatype : "json",
                    success : function(result) {
                        c = eval(result);
                    }
                });
                console.log(c)
                $("#name").val(row.doornumber);
                $("#money").val(c.money);
                $("#date").val(c.kdate);
                $("#xuan").val(c.chanquan);
                $("#sfz").val(c.sfz);
                $("#uname").val(c.name);
                $("#phone").val(c.phone);
                $("#remark").val(c.remark);
                $("#yin").val(c.id);
                $("#yin2").val(row.id);
            }
        },
        contentType:"application/x-www-form-urlencoded",
        queryParamsType: '',
        //修改分页的默认对数
        //offset,limit
        height: 700,
        pageNumber: 1,
        pageSize: 15,
        pagination:true,
        queryParams: queryParams,
        sidePagination:'server',
    });


})

function search() {
    var opt = $("#table").bootstrapTable('getOptions');

    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }
    var type = $("#typexuan").val();
    var men = $("#men").val();
    var huxing=$("#huxing").val();

    $.post('${pageContext.request.contextPath}/../../house/list', {
        'shu':shu,
        'type': type,
        /*'huxing':huxing,*/
        'number':men,
        'pageSize': opt.pageSize,
        'pageNumber': 1
    }, function (data) {

        //重新给table绑定数据
        $("#table").bootstrapTable("load", data);
    });
}


function queryParams(params) {
    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }
    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        'pageSize': params.pageSize,  //页面大小
        'pageNumber': params.pageNumber, //页码
        'shu':shu,
       /* 'huxing':$('#huxing').val(),*/
        'type' :$ ('#typexuan').val(),
        'number':$("#men").val(),
    };
    return temp;
};